/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package umled.model;

import java.awt.Graphics2D;
import org.w3c.dom.*;
/**
 *
 * @author ANor
 */
public class UMLData extends UMLComponent {
    private UMLType type;
    private String defaultValue;
    
    public UMLData(String name, UMLElement parent, int xPos, int yPos, int width, int height, UMLVisible v, UMLType type, String defaultValue){
        super(name, parent, xPos, yPos, width, height, v);
        this.defaultValue = defaultValue;
        this.type = type;
    }
    public void setDefoultValue(String value){
        defaultValue = value;
    }
    public String getDefoultValue(){
        return defaultValue;
    }
    public UMLType getType(){
        return type;
    }
    public void setType(UMLType type){
        this.type = type;
    }
    public void draw(Graphics2D g2d, int x, int y){
        drawRectangle( g2d, getX(), getY(), getWidth(), getHeight(), x, y);
        drawString( g2d, toString(), getX() + 10, getY() + 12, x, y);
    }
    @Override
    public String toString(){
        StringBuilder sb = new StringBuilder();
        sb.append( getVisible() ).append( getName() ).append(" : ").append( getType() );
        if( !defaultValue.equals(""))
            sb.append("=").append( defaultValue );
        return sb.toString();
    }
    /**
     * Returns XML-represention of current Data-element
     * @param document to which this Data-element will be appended
     * @return XML-represention of current Data-element
     */
    @Override
    public Element getXML( Document document ){
        Element element = super.getXML( document );
        element.setAttribute( "type" , "UMLData" );
        
        Element temp = document.createElement( "Default Value" );
        temp.appendChild( document.createTextNode( defaultValue ) );
        element.appendChild(temp);
        
        //must be rewritten
        temp = document.createElement( "Type" );
        temp.appendChild( document.createTextNode( type.getName() ) );
        element.appendChild(temp);
        
        return element;
    }
}
